package java_test.newfeatures;

import java.util.Optional;

public class OptionalTest {
    public static void main(String[] args) {
//        Optional<Girl> girl = Optional.of(new Girl());
//        Optional<Object> o = Optional.ofNullable(null);
        Boy boy = new Boy();
        System.out.println(getGirlName(boy));
    }

    public static String getGirlName(Boy boy) {
        return boy.getGirl().getName();
    }

    public static String getGirlName1(Boy boy) {
        Optional<Boy> boy1 = Optional.ofNullable(boy);
        Boy boy2 = boy1.orElse(new Boy(new Girl("迪丽热巴")));
        Girl girl = boy2.getGirl();
        Optional<Girl> girl1 = Optional.ofNullable(girl);
        Girl girl2 = girl1.orElse(new Girl("古力娜扎"));

        return girl2.getName();
    }
}
